//
//  RealComplayAuthenticationTabVC.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/1.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "RealComplayAuthenticationTabVC.h"
#import "WriteRequirementTitleCell.h"
#import "TextFieldCell.h"
#import "UITextView+Placeholder.h"
#import "ButtonCell.h"
#import "UpdateImageCell.h"
#import "RealComplayAuthenticationSubTabVC.h"
#import "CustomePickerImageVC.h"
#import "TZImagePickerController.h"
#import "AuthenticationModel.h"
@interface RealComplayAuthenticationTabVC ()<ButtonCellDelegate,UpdateImageCellDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,TZImagePickerControllerDelegate,TextFieldCellDelegate>
@property(nonatomic,strong) AuthenticationModel *authenticationModel;
@property(nonatomic,strong) NSDictionary *dict;
@property(nonatomic,strong) AuthenticationModel *authModel;

@end
static NSString *identifierTitle = @"WriteRequirementTitleCell";
static NSString *identifierNamed = @"TextViewCell";
static NSString *identifierTextField = @"TextFieldCell";
static NSString *identifierBtn = @"ButtonCell";
static NSString *identifierUpdateImage = @"UpdateImageCell";
@implementation RealComplayAuthenticationTabVC
- (void)viewDidLoad {
    [super viewDidLoad];
    if (!self.realPerson) {
        self.navigationItem.title = @"企业实名认证";
    }else {
        self.navigationItem.title = @"个人实名认证";
    }
    self.authenticationModel = [[AuthenticationModel alloc]init];
    [self.tableView registerNib:[UINib nibWithNibName:@"WriteRequirementTitleCell" bundle:nil] forCellReuseIdentifier:identifierTitle];
    [self.tableView registerNib:[UINib nibWithNibName:@"TextFieldCell" bundle:nil] forCellReuseIdentifier:identifierTextField];
    [self.tableView registerNib:[UINib nibWithNibName:@"ButtonCell" bundle:nil] forCellReuseIdentifier:identifierBtn];
    [self.tableView registerNib:[UINib nibWithNibName:@"UpdateImageCell" bundle:nil] forCellReuseIdentifier:identifierUpdateImage];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkCertification:) name:@"checkCertification" object:nil];
}
- (void)setShowMsg:(BOOL)showMsg
{
    _showMsg = showMsg;
    if (showMsg) {
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      @"status":[NumberSwitchString numberSwitchString:self.status]
                      };
        XLog(@"self.dict:%@",self.dict);
        self.authModel = [[AuthenticationModel alloc]init];
        [CustomeManager POSTWithURLIndex:75 parameters:self.dict success:^(NSDictionary *dict) {
            
        } failure:^(NSError *error) {
            
        }];
    }else {
    }
}
-(void)checkCertification:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"dict:%@",dict);
    NSDictionary *date = [dict objectForKey:@"date"];
    self.authModel = [AuthenticationModel mj_objectWithKeyValues:date];
    [self.tableView reloadData];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     if (!self.realPerson) {
         return 9;
     }else {
         return 5;
     }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    if (!self.realPerson) {
        if (indexPath.row == 0||indexPath.row == 2||indexPath.row == 4||indexPath.row == 6) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierTitle forIndexPath:indexPath];
            if (indexPath.row == 0) {
                cell.titleL.text = @"公司名称";
            }else if (indexPath.row == 2) {
                cell.titleL.text = @"公司联系方式";
            }else if (indexPath.row == 4) {
                cell.titleL.text = @"统一社会信用代码";
            }else {
                cell.titleL.text = @"上传或拍摄营业执照扫描件或照片";
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 1||indexPath.row == 3||indexPath.row == 5) {
            TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierTextField forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (indexPath.row == 1) {
                cell.tf.placeholder = @"认证成功后不可更改";
                if (self.showMsg) {
                    cell.userInteractionEnabled = NO;
                    cell.tf.text = self.authModel.companyname;
                }
            }else if (indexPath.row == 3) {
                cell.tf.placeholder = @"座机号或手机号，座机请加区号";
                if (self.showMsg) {
                    cell.userInteractionEnabled = NO;
                    cell.tf.text = self.authModel.mobile;
                }
            }else {
                cell.tf.placeholder = @"营业执照上18位统一社会信用代码";
                if (self.showMsg) {
                    cell.userInteractionEnabled = NO;
                    cell.tf.text = self.authModel.societycreditcode;
                }
            }
            cell.indexPath = indexPath;
            cell.delegate = self;
            cell.tf.layer.cornerRadius = 3;
            cell.tf.layer.borderColor  = kOrangeBg.CGColor;
            cell.tf.layer.borderWidth  = 1;
            cell.lineL.hidden = YES;
            return cell;
        }else if (indexPath.row == 7) {
            UpdateImageCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierUpdateImage forIndexPath:indexPath];
            if (self.showMsg) {
                cell.userInteractionEnabled = NO;
                [cell.clickBtn sd_setImageWithURL:[NSURL URLWithString:self.authModel.commanyicon] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"noDataImg"]];
            }
            cell.delegate = self;
            return cell;
        }else {
            ButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierBtn   forIndexPath:indexPath];
            [cell.btn setTitle:@"下一步" forState:UIControlStateNormal];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.delegate = self;
            return cell;
        }
    }else {
        if (indexPath.row == 0||indexPath.row == 2) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierTitle forIndexPath:indexPath];
            if (indexPath.row == 0) {
                cell.titleL.text = @"姓名";
            }else{
                cell.titleL.text = @"身份证号";
            }
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else if (indexPath.row == 1||indexPath.row == 3) {
            TextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierTextField forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (indexPath.row == 1) {
                cell.tf.placeholder = @"认证成功后不可更改";
                if (self.showMsg) {
                    cell.userInteractionEnabled = NO;
                    cell.tf.text = self.authModel.name;
                }
                
            }else if (indexPath.row == 3) {
                cell.tf.placeholder = @"15位或18位身份证号";
                if (self.showMsg) {
                    cell.userInteractionEnabled = NO;
                    cell.tf.text = self.authModel.idnum;
                }
            }
            cell.indexPath = indexPath;
            cell.delegate = self;
            cell.tf.layer.cornerRadius = 3;
            cell.tf.layer.borderColor  = [UIColor colorWithRed:151/255.0 green:193/255.0 blue:91/255.0 alpha:1].CGColor;
            cell.tf.layer.borderWidth  = 1;
            cell.lineL.hidden = YES;
            
            return cell;
        }else {
            ButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierBtn   forIndexPath:indexPath];
            [cell.btn setTitle:@"下一步" forState:UIControlStateNormal];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.btn setBackgroundColor:[UIColor colorWithRed:151/255.0 green:193/255.0 blue:91/255.0 alpha:1]];
            cell.delegate = self;
            return cell;
        }
    }
    
}
#pragma mark-代理:公司,公司联系,社会信用代码
- (void)textFieldCell:(TextFieldCell *)textFieldCell withTextField:(UITextField *)tf withIndexPath:(NSIndexPath *)indexPath
{
     if (!self.realPerson) {
         if (indexPath.row == 1) {
             self.authenticationModel.companyname = tf.text;
         }else if (indexPath.row == 3) {
             self.authenticationModel.mobile = tf.text;
         }else {
             self.authenticationModel.societycreditcode = tf.text;
         }
     }else {
         if (indexPath.row == 1) {
             self.authenticationModel.name = tf.text;
         }else if (indexPath.row == 3) {
             if (tf.text.length >18) {
                 tf.text = [tf.text substringToIndex:18];
             }
             self.authenticationModel.idnum = tf.text;
         }
     }
}
#pragma mark-代理:上传图片
- (void)updateImageCell:(UpdateImageCell *)updateImageCell withBtn:(UIButton *)btn
{
    //打开照相机和图片
    UIAlertController *sheetControler = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    CustomePickerImageVC *picker = [[CustomePickerImageVC alloc]init];
    
    picker.edgesForExtendedLayout =  UIRectEdgeNone;
    picker.automaticallyAdjustsScrollViewInsets = NO;
    
    picker.allowsEditing = YES;
    
    picker.delegate = self;
    sheetControler.popoverPresentationController.sourceView = self.view;
    sheetControler.popoverPresentationController.sourceRect = self.view.frame;
//    UIAlertAction *paizhao = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
////        [self takePhoto];
//        //先push一个控制器(在这个控制器里面可以编辑图片)
//        
//        [self presentViewController:picker animated:YES completion:nil];
//    }];
//    UIAlertAction *xiangce = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self pushTZImagePickerController];
//    }];
//    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//        //XLog(@"cancel");
//    }];
//    [sheetControler addAction:paizhao];
//    [sheetControler addAction:xiangce];
//    [sheetControler addAction:cancel];
    [self presentViewController:sheetControler animated:YES completion:nil] ;
}
- (void)pushTZImagePickerController {
    NSIndexPath *indexPath = [[NSIndexPath alloc]init];
    if (!self.realPerson) {
        indexPath = [NSIndexPath indexPathForRow:7 inSection:0];
    }else {
    }
    UpdateImageCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *urlString = @"http://www.qichangkeji.vip/upload/upload?savePath=img";
    
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self pushPhotoPickerVc:YES];

    [imagePickerVc setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }];

    imagePickerVc.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
    imagePickerVc.showPhotoCannotSelectLayer = YES;
    imagePickerVc.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
    [imagePickerVc setPhotoPickerPageUIConfigBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {
        [doneButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }];

    imagePickerVc.allowPickingImage = YES;
    imagePickerVc.allowPickingOriginalPhoto = YES;
    imagePickerVc.allowPickingGif = NO;
    imagePickerVc.allowPickingMultipleVideo = NO; // 是否可以多选视频
    imagePickerVc.allowTakePicture = YES;
    // 4. 照片排列按修改时间升序
    imagePickerVc.sortAscendingByModificationDate = YES;
    
    // imagePickerVc.minImagesCount = 3;
    // imagePickerVc.alwaysEnableDoneBtn = YES;
    
    // imagePickerVc.minPhotoWidthSelectable = 3000;
    // imagePickerVc.minPhotoHeightSelectable = 2000;
    
    /// 5. Single selection mode, valid when maxImagesCount = 1
    /// 5. 单选模式,maxImagesCount为1时才生效
    imagePickerVc.showSelectBtn = NO;
    imagePickerVc.allowCrop = NO;
    imagePickerVc.needCircleCrop = NO;
    // 设置竖屏下的裁剪尺寸
    //    NSInteger left = 30;
    //    NSInteger widthHeight = kVWidth - 2 * left;
    //    NSInteger top = (kVWidth - widthHeight) / 2;
    //    imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
    
    imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
    
    // 设置是否显示图片序号
    imagePickerVc.showSelectedIndex = YES;
    
    
    // 设置首选语言 / Set preferred language
    // imagePickerVc.preferredLanguage = @"zh-Hans";
    
    // 设置languageBundle以使用其它语言 / Set languageBundle to use other language
    // imagePickerVc.languageBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"tz-ru" ofType:@"lproj"]];
    
#pragma mark - 到这里为止
    
    // You can get the photos by block, the same as by delegate.
    // 你可以通过block或者代理，来得到用户选择的照片.
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        XLog(@"photos:%@",photos);
        /**
         2018-12-06 16:07:48.463518+0800 BusinessMarket[789:89872] photos:(
         "<UIImage: 0x2829bd340> size {750, 1206} orientation 0 scale 1.000000"
         )
         */
        UIImage *image = photos[0];
        NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
        [cell.clickBtn setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        //选择回调
//        [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
//        [WSProgressHUD show];
//        self.tableView.userInteractionEnabled = NO;
        [manager POST:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            //
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            formatter.dateFormat = @"yyyyMMddHHmmss";
            NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];
            //二进制文件，接口key值，文件路径，图片格式
            [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpg/png/jpeg"];
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            float update = uploadProgress.fractionCompleted*100;
            XLog(@"%f",update);
            XLog(@"%.f%%",update);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [WSProgressHUD showWithStatus:[NSString stringWithFormat:@"%.f%%",update]];
                
            });
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            XLog(@"responseObject:%@",responseObject);
            NSString *stringImg = [responseObject mj_JSONString];
            NSDictionary *dict = [stringImg mj_JSONObject];
            XLog(@"stringImg:%@",stringImg);
            self.authenticationModel.commanyicon = [dict objectForKey:@"path"];
            [WSProgressHUD dismiss];
//            self.tableView.userInteractionEnabled = YES;
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [WSProgressHUD dismiss];
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"图片上传失败,请重新上传"];
//            self.tableView.userInteractionEnabled = YES;
        }];
    }];
    
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}
//- (void)takePhoto {
//    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
//    XLog(@"authStatus:%ld",(long)authStatus);
//    if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
//        // 无相机权限 做一个友好的提示
//        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消1" otherButtonTitles:@"设置1", nil];
//        [alert show];
//    } else if (authStatus == AVAuthorizationStatusNotDetermined) {
//        // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
//        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
//            if (granted) {
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    [self takePhoto];
//                });
//            }
//        }];
//        // 拍照之前还需要检查相册权限
//    }else if ([PHPhotoLibrary authorizationStatus] == 0) { // 未请求过相册权限
//        [[TZImageManager manager] requestAuthorizationWithCompletion:^{
//            [self takePhoto];
//        }];
//    } else {
//        [self pushImagePickerController];
//    }
//}

// 调用相机
- (void)pushImagePickerController {
    
    // 提前定位
    __weak typeof(self) weakSelf = self;
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *imagePickerVc = [[UIImagePickerController alloc] init];
        imagePickerVc.delegate = self;
        imagePickerVc.sourceType = sourceType;
        
        //        NSMutableArray *mediaTypes = [NSMutableArray array];
        //        if (self.showTakePhotoBtnSwitch.isOn) {
        //            [mediaTypes addObject:(NSString *)kUTTypeImage];
        //        }
        //        if (mediaTypes.count) {
        //            _imagePickerVc.mediaTypes = mediaTypes;
        //        }
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    } else {
        //        NSLog(@"模拟器中无法打开照相机,请在真机中使用");
    }
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
    tzImagePickerVc.sortAscendingByModificationDate = YES;
    [tzImagePickerVc showProgressHUD];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    
    
    NSIndexPath *indexPath = [[NSIndexPath alloc]init];
    if (!self.realPerson) {
        indexPath = [NSIndexPath indexPathForRow:7 inSection:0];
    }else {
    }
    UpdateImageCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
    [cell.clickBtn setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *urlString = @"http://www.qichangkeji.vip/upload/upload?savePath=img";
    //选择回调
//    [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
//    [WSProgressHUD show];
    self.tableView.userInteractionEnabled = NO;
    [manager POST:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        //
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];
        //二进制文件，接口key值，文件路径，图片格式
        [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpg/png/jpeg"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        float update = uploadProgress.fractionCompleted*100;
        XLog(@"%f",update);
        XLog(@"%.f%%",update);
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [WSProgressHUD showWithStatus:[NSString stringWithFormat:@"%.f%%",update]];
            
        });
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        XLog(@"responseObject:%@",responseObject);
        NSString *stringImg = [responseObject mj_JSONString];
        NSDictionary *dict = [stringImg mj_JSONObject];
        XLog(@"stringImg:%@",stringImg);
        self.authenticationModel.commanyicon = [dict objectForKey:@"path"];
        [WSProgressHUD dismiss];
        self.tableView.userInteractionEnabled = YES;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        [WSProgressHUD dismiss];
        [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"图片上传失败,请重新上传"];
        self.tableView.userInteractionEnabled = YES;
    }];
    [picker dismissViewControllerAnimated:YES completion:nil];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.realPerson) {
        if (indexPath.row == 0||indexPath.row == 2||indexPath.row == 4||indexPath.row == 6) {
            return 60;
        }else if(indexPath.row == 1||indexPath.row == 3||indexPath.row == 5) {
            return 44;
        }else if(indexPath.row == 8) {
            return 100;
        }else
        {
            return 184;
        }
    }else {
        if (indexPath.row == 0||indexPath.row == 2) {
            return 60;
        }else if(indexPath.row == 1||indexPath.row == 3) {
            return 44;
        }else
        {
            return 200;
        }
    }
   
}
#pragma mark-代理---下一步
- (void)buttonCell:(ButtonCell *)buttonCell withClickBtn:(UIButton *)clickBtn
{
    if (!self.realPerson&&!self.showMsg) {
        if (self.authenticationModel.companyname.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请输入公司名称"];
        }else if (self.authenticationModel.mobile.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请输入公司联系方式"];
        }else if (self.authenticationModel.societycreditcode.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请输入统一社会信用代码"];
        }else if (self.authenticationModel.commanyicon.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请上传营业执照"];
        }else {
            realPersonAuthenticationSubTabVC *vc = [[realPersonAuthenticationSubTabVC alloc]init];
            vc.authenticationModel = self.authenticationModel;
            vc.realPerson = self.realPerson;
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }else if (self.realPerson&&!self.showMsg) {
        if (self.authenticationModel.name.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请输入您的姓名"];
        }else if (self.authenticationModel.idnum.length == 0) {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"请输入您的身份证号"];
        }else {
            realPersonAuthenticationSubTabVC *vc = [[realPersonAuthenticationSubTabVC alloc]init];
            vc.authenticationModel = self.authenticationModel;
            vc.realPerson = self.realPerson;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }else {
        realPersonAuthenticationSubTabVC *vc = [[realPersonAuthenticationSubTabVC alloc]init];
        vc.authenticationModel = self.authenticationModel;
        vc.realPerson = self.realPerson;
        vc.showMsg = self.showMsg;
        vc.authModel = self.authModel;
        [self.navigationController pushViewController:vc animated:YES];
    }
    XLog(@"%@",_authenticationModel);
    
}
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
}
@end
